﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{ 
    public class EKGBData : BaseFunction
    { 
        public EKGBData()
            : base()
        {

        }

        public EKGBData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }

        public DataSet BuildData()
        {
            DataSet setReturn = new DataSet();
            DataSet dsResult = new DataSet();
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT CODE,GLLB,ART,VAR,COLOR,SUPPLIER,INCOMEDATE,BATCH,SUPPLIERBATCH, "
                + " SUM(WEI) AS WEI FROM INVENTORY_YARN_REPORT_LB "
                + " group by CODE,GLLB,ART,VAR,COLOR,SUPPLIER,INCOMEDATE,BATCH,SUPPLIERBATCH ";

                dsResult = Connect2Proxy(orlReadCommand);
                if (dsResult.Tables.Count > 0)
                {
                    dsResult.Tables[0].TableName = "INVENTORY_YARN";
                }
                byte[] b;
                string value;
                string ColumnName = "";
                foreach (DataRow dw in dsResult.Tables["INVENTORY_YARN"].Rows)
                {
                    ColumnName = "COLOR";

                    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw[ColumnName].ToString().Trim());
                    value = Encoding.GetEncoding("gb2312").GetString(b);
                    dw[ColumnName] = value;

                    ColumnName = "SUPPLIER";
                    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw[ColumnName].ToString().Trim());
                    value = Encoding.GetEncoding("gb2312").GetString(b);
                    dw[ColumnName] = value;
                }
                setReturn.Merge(dsResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}